package com.kd.sms.config;

import com.kd.sms.ISmsProvider;
import com.kd.sms.provider.aliyun.AliYunSmsProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SmsProperties.class)
public class AutoConfiguration {

    @Bean
    public ISmsProvider getSmsProvider(@Autowired SmsProperties smsProperties)  throws Exception {
        return smsProperties.getProvider() != null ? (ISmsProvider) smsProperties.getProvider().newInstance() : new AliYunSmsProvider();
    }
}
